#ifndef SingletonHolder_INCLUDED
#define SingletonHolder_INCLUDED

#include "mutex.h"

template <class S>
class SingletonHolder
{
public:
    SingletonHolder():
        m_pS(NULL),m_mutex(true)
    {}
    
    ~SingletonHolder()
    { delete m_pS;}
    
    S* get()
    {
        ScopedMutex tmp(&m_mutex);
        if (!m_pS) m_pS = new S;
        return m_pS;
    }
    
private:
    S* m_pS;
    Mutex m_mutex;
};

#endif



